class AdressModel {
  final int code;
  final String msg;
  final List<AdressInfo>? data;

  AdressModel({
    required this.code,
    required this.msg,
    this.data,
  });

  factory AdressModel.fromJson(Map<String, dynamic> json) {
    return AdressModel(
      code: json['code'],
      msg: json['msg'],
      data: (json['data'] as List?)?.map((e) => AdressInfo.fromJson(e)).toList(),
    );
  }
}

class AdressInfo {
  final int id;
  final int memberId;
  final String firstName;
  final String lastName;
  final String phoneNumber;
  final String phoneCode;
  final String? country;
  final int? countryId;
  final String? state;
  final String city;
  final String zipCode;
  final String email;
  final int type;
  final String address1;
  final String address2;
  final String defaultAddress;

  AdressInfo({
    required this.id,
    required this.memberId,
    required this.firstName,
    required this.lastName,
    required this.phoneNumber,
    required this.phoneCode,
    this.country,
    this.countryId,
    this.state,
    required this.city,
    required this.zipCode,
    required this.email,
    required this.type,
    required this.address1,
    required this.address2,
    required this.defaultAddress,
  });

  factory AdressInfo.fromJson(Map<String, dynamic> json) {
    return AdressInfo(
      id: json['id'],
      memberId: json['memberId'],
      firstName: json['firstName'],
      lastName: json['lastName'],
      phoneNumber: json['phoneNumber'],
      phoneCode: json['phoneCode'],
      country: json['country'],
      countryId: json['countryId'],
      state: json['state'],
      city: json['city'],
      zipCode: json['zipCode'],
      email: json['email'],
      type: json['type'],
      address1: json['address1'],
      address2: json['address2'],
      defaultAddress: json['defaultAddress'],
    );
  }
}

class CardModel {
  int code;
  String msg;
  List<CardInfo>? data;

  CardModel({
    required this.code,
    required this.msg,
    this.data,
  });

  // 手动从 JSON 转换为 CardModel
  factory CardModel.fromJson(Map<String, dynamic> json) {
    return CardModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: json['data'] != null
          ? List<CardInfo>.from(json['data'].map((x) => CardInfo.fromJson(x)))
          : null,
    );
  }

  // 手动转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'msg': msg,
      'data': data != null ? List<dynamic>.from(data!.map((x) => x.toJson())) : null,
    };
  }
}

class CardInfo {
  String cardNo;
  String paymentConsentId;

  CardInfo({
    required this.cardNo,
    required this.paymentConsentId,
  });

  // 手动从 JSON 转换为 CardInfo
  factory CardInfo.fromJson(Map<String, dynamic> json) {
    return CardInfo(
      cardNo: json['cardNo'] ?? '',
      paymentConsentId: json['paymentConsentId'] ?? '',
    );
  }

  // 手动转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'cardNo': cardNo,
      'paymentConsentId': paymentConsentId,
    };
  }
}
